# 线段树超时
# class Bitset(object):
#
#     def __init__(self, size):
#         """
#         :type size: int
#         """
#         self.n = size
#         self.p = [0] * 4 * self.n
#         self.lazy = [0] * 4 * self.n
#
#     def down(self, node, ls, rs):
#         if self.lazy[node]:
#             mid = (ls + rs) // 2
#             self.lazy[2 * node + 1] = (self.lazy[2 * node + 1] + 1) % 2
#             self.lazy[2 * node + 2] = (self.lazy[2 * node + 2] + 1) % 2
#             self.p[2 * node + 1] = mid - ls + 1 - self.p[2 * node + 1]
#             self.p[2 * node + 2] = rs - mid - self.p[2 * node + 2]
#             self.lazy[node] = 0
#
#     def update(self, node, ls, rs, id, val):
#         if ls == rs:
#             self.lazy[node] = 0
#             self.p[node] = val
#         else:
#             self.down(node, ls, rs)
#             mid = (ls + rs) // 2
#             if id <= mid:
#                 self.update(2 * node + 1, ls, mid, id, val)
#             else:
#                 self.update(2 * node + 2, mid + 1, rs, id, val)
#             self.p[node] = self.p[2 * node + 1] + self.p[2 * node + 2]
#
#     def query(self, node, ls, rs, id):
#         if ls == rs:
#             return self.p[node]
#         else:
#             self.down(node, ls, rs)
#             mid = (ls + rs) // 2
#             if id <= mid:
#                 r_val = self.query(2 * node + 1, ls, mid, id)
#             else:
#                 r_val = self.query(2 * node + 2, mid + 1, rs, id)
#             self.p[node] = self.p[2 * node + 1] + self.p[2 * node + 2]
#             return r_val
#
#     def fix(self, idx):
#         """
#         :type idx: int
#         :rtype: None
#         """
#         self.update(0, 0, self.n - 1, idx, 1)
#
#     def unfix(self, idx):
#         """
#         :type idx: int
#         :rtype: None
#         """
#         self.update(0, 0, self.n - 1, idx, 0)
#
#     def flip(self):
#         """
#         :rtype: None
#         """
#         self.p[0] = self.n - self.p[0]
#         self.lazy[0] = (self.lazy[0] + 1) % 2
#
#     def all(self):
#         """
#         :rtype: bool
#         """
#         return self.p[0] == self.n
#
#     def one(self):
#         """
#         :rtype: bool
#         """
#         return self.p[0] > 0
#
#     def count(self):
#         """
#         :rtype: int
#         """
#         return self.p[0]
#
#     def toString(self):
#         """
#         :rtype: str
#         """
#         ans = []
#         for i in range(self.n):
#             ans.append(str(self.query(0, 0, self.n - 1, i)))
#         return ''.join(ans)


# 懒标记解法
class Bitset(object):

    def __init__(self, size):
        """
        :type size: int
        """
        self.lazy = 0
        self.n = size
        self.ans = [0] * self.n
        self.t = 0

    def fix(self, idx):
        """
        :type idx: int
        :rtype: None
        """
        if self.lazy:
            if self.ans[idx] == 1:
                self.t += 1
            self.ans[idx] = 0
        else:
            if self.ans[idx] == 0:
                self.t += 1
            self.ans[idx] = 1


    def unfix(self, idx):
        """
        :type idx: int
        :rtype: None
        """
        if self.lazy:
            if self.ans[idx] == 0:
                self.t -= 1
            self.ans[idx] = 1
        else:
            if self.ans[idx] == 1:
                self.t -= 1
            self.ans[idx] = 0

    def flip(self):
        """
        :rtype: None
        """
        self.lazy = (self.lazy + 1) % 2
        self.t = self.n - self.t

    def all(self):
        """
        :rtype: bool
        """
        return self.t == self.n

    def one(self):
        """
        :rtype: bool
        """
        return self.t > 0

    def count(self):
        """
        :rtype: int
        """
        return self.t

    def toString(self):
        """
        :rtype: str
        """
        if self.lazy:
            for i in range(self.n):
                self.ans[i] = 1 - self.ans[i]
            self.lazy = 0
        r = [str(item) for item in self.ans]
        return ''.join(r)
